package com.abc.pay.client;

import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;

public class HiCalendar extends GregorianCalendar {
    public static final int YEAR = 1;
    public static final int MONTH = 2;
    public static final int DATE = 5;
    public static final int HOUR = 10;
    public static final int MINUTE = 12;
    public static final int SECOND = 13;
    protected static String[] sMonthName = new String[]{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
    protected static String[] sWeekName = new String[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
    protected static String[] sLocalMonthName = new String[]{"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"};
    protected static String[] sLocalWeekName = new String[]{"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
    protected static String[] sShortMonthName = new String[]{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
    protected static String[] sShortWeekName = new String[]{"Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat"};
    protected static String[] sLocalShortMonthName = new String[]{"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"};
    protected static String[] sLocalShortWeekName = new String[]{"日", "一", "二", "三", "四", "五", "六"};

    public HiCalendar() {
    }

    public HiCalendar(int aYear, int aMonth, int aDate) {
        super(aYear, aMonth, aDate);
    }

    public HiCalendar(int aYear, int aMonth, int aDate, int aHour, int aMinute) {
        super(aYear, aMonth, aDate, aHour, aMinute);
    }

    public HiCalendar(int aYear, int aMonth, int aDate, int aHour, int aMinute, int aSecond) {
        super(aYear, aMonth, aDate, aHour, aMinute, aSecond);
    }

    public HiCalendar(Locale aLocale) {
        super(aLocale);
    }

    public HiCalendar(TimeZone aZone) {
        super(aZone);
    }

    public HiCalendar(TimeZone aZone, Locale aLocale) {
        super(aZone, aLocale);
    }

    public boolean equals(Object obj) {
        return super.equals(obj);
    }

    protected void finalize() throws Throwable {
        super.finalize();
    }

    public int hashCode() {
        return super.hashCode();
    }

    public String toString() {
        return super.toString();
    }

    public String toString(String aTimeFormat) {
        int tFormatLength = aTimeFormat.length();
        int tValue;
        String tString;
        String tFormatedString = "";
        for(int i = 0; i < tFormatLength; ++i) {
            if (aTimeFormat.charAt(i) == '%' && i != tFormatLength - 1) {
                ++i;
                switch (aTimeFormat.charAt(i)) {
                    case 'A':
                        tFormatedString = tFormatedString + sWeekName[this.get(7) - 1];
                        break;
                    case 'B':
                        tFormatedString = tFormatedString + sMonthName[this.get(2)];
                        break;
                    case 'C':
                    case 'D':
                    case 'E':
                    case 'F':
                    case 'G':
                    case 'J':
                    case 'K':
                    case 'N':
                    case 'O':
                    case 'P':
                    case 'Q':
                    case 'R':
                    case 'T':
                    case 'V':
                    case '[':
                    case '\\':
                    case ']':
                    case '^':
                    case '_':
                    case '`':
                    case 'e':
                    case 'f':
                    case 'g':
                    case 'h':
                    case 'i':
                    case 'k':
                    case 'l':
                    case 'n':
                    case 'o':
                    case 'q':
                    case 'r':
                    case 's':
                    case 't':
                    case 'u':
                    case 'v':
                    default:
                        tFormatedString = tFormatedString + aTimeFormat.charAt(i);
                        break;
                    case 'H':
                        tValue = this.get(11);
                        if (tValue < 10) {
                            tFormatedString = tFormatedString + "0";
                        }
                        tFormatedString = tFormatedString + String.valueOf(tValue);
                        break;
                    case 'I':
                        tValue = this.get(10);
                        if (tValue < 10) {
                            tFormatedString = tFormatedString + "0";
                        }
                        tFormatedString = tFormatedString + String.valueOf(tValue);
                        break;
                    case 'L':
                        if (i != tFormatLength - 1) {
                            ++i;
                            switch (aTimeFormat.charAt(i)) {
                                case 'A':
                                    tFormatedString = tFormatedString + sLocalWeekName[this.get(7) - 1];
                                    break;
                                case 'B':
                                    tFormatedString = tFormatedString + sLocalMonthName[this.get(2)];
                                    break;
                                case 'Y':
                                    tValue = this.get(1) - 1911;
                                    tFormatedString = tFormatedString + String.valueOf(tValue) + "年";
                                    break;
                                case 'a':
                                    tFormatedString = tFormatedString + sLocalShortWeekName[this.get(7) - 1];
                                    break;
                                case 'b':
                                    tFormatedString = tFormatedString + sLocalShortMonthName[this.get(2)];
                                    break;
                                case 'y':
                                    tValue = this.get(1) - 1911;
                                    tFormatedString = tFormatedString + String.valueOf(tValue);
                                    break;
                                default:
                                    tFormatedString = tFormatedString + aTimeFormat.charAt(i);
                            }
                        }
                        break;
                    case 'M':
                        tValue = this.get(12);
                        if (tValue < 10) {
                            tFormatedString = tFormatedString + "0";
                        }
                        tFormatedString = tFormatedString + String.valueOf(tValue);
                        break;
                    case 'S':
                        tValue = this.get(13);
                        if (tValue < 10) {
                            tFormatedString = tFormatedString + "0";
                        }
                        tFormatedString = tFormatedString + String.valueOf(tValue);
                        break;
                    case 'U':
                        tValue = this.get(3);
                        GregorianCalendar tCalendar = new GregorianCalendar(this.get(1), 0, 1);
                        if (tCalendar.get(7) == 2) {
                            --tValue;
                        }
                        if (tValue < 10) {
                            tFormatedString = tFormatedString + "0";
                        }
                        tFormatedString = tFormatedString + String.valueOf(tValue);
                        break;
                    case 'W':
                        tValue = this.get(3);
                        if (tValue < 10) {
                            tFormatedString = tFormatedString + "0";
                        }
                        tFormatedString = tFormatedString + String.valueOf(tValue);
                        break;
                    case 'X':
                        tFormatedString = tFormatedString + this.toString("%H:%M:%S");
                        break;
                    case 'Y':
                        tValue = this.get(1);
                        tFormatedString = tFormatedString + String.valueOf(tValue);
                        break;
                    case 'Z':
                        tFormatedString = tFormatedString + this.getTimeZone().getID();
                        break;
                    case 'a':
                        tFormatedString = tFormatedString + sShortWeekName[this.get(7) - 1];
                        break;
                    case 'b':
                        tFormatedString = tFormatedString + sShortMonthName[this.get(2)];
                        break;
                    case 'c':
                        tFormatedString = tFormatedString + this.toString("%x %X");
                        break;
                    case 'd':
                        tValue = this.get(5);
                        if (tValue < 10) {
                            tFormatedString = tFormatedString + "0";
                        }
                        tFormatedString = tFormatedString + String.valueOf(tValue);
                        break;
                    case 'j':
                        tValue = this.get(6);
                        if (tValue < 10) {
                            tFormatedString = tFormatedString + "0";
                        }
                        tFormatedString = tFormatedString + String.valueOf(tValue);
                        break;
                    case 'm':
                        tValue = this.get(2) + 1;
                        if (tValue < 10) {
                            tFormatedString = tFormatedString + "0";
                        }
                        tFormatedString = tFormatedString + String.valueOf(tValue);
                        break;
                    case 'p':
                        if (this.get(1) == 1) {
                            tFormatedString = tFormatedString + "AM";
                        } else {
                            tFormatedString = tFormatedString + "PM";
                        }
                        break;
                    case 'w':
                        tValue = this.get(7) - 1;
                        if (tValue < 10) {
                            tFormatedString = tFormatedString + "0";
                        }
                        tFormatedString = tFormatedString + String.valueOf(tValue);
                        break;
                    case 'x':
                        tFormatedString = tFormatedString + this.toString("%m/%d/%y");
                        break;
                    case 'y':
                        tValue = this.get(1);
                        tString = String.valueOf(tValue);
                        tFormatedString = tFormatedString + tString.substring(2, 4);
                }
            } else {
                tFormatedString = tFormatedString + aTimeFormat.charAt(i);
            }
        }

        return tFormatedString;
    }
}
